package com.zrwl.poscloud.core.restapi.admin.baseInfo;

import com.zrwl.poscloud.core.annotion.AuthorityVerify.AuthorityVerify;
import com.zrwl.poscloud.core.annotion.OperationLogger.OperationLogger;
import com.zrwl.poscloud.core.config.admin.LocalApiConfig;
import com.zrwl.poscloud.commons.exception.ThrowableUtils;
import com.zrwl.poscloud.commons.utils.ResultUtil;
import com.zrwl.poscloud.commons.validator.group.Delete;
import com.zrwl.poscloud.commons.validator.group.GetList;
import com.zrwl.poscloud.commons.validator.group.Insert;
import com.zrwl.poscloud.commons.validator.group.Update;
import com.zrwl.poscloud.xo.service.CompanyAdminRService;
import com.zrwl.poscloud.xo.vo.CompanyAdminRVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 商户管理员 controller api类
 *
 * @author 刘思童 AutoGenerate
 * @date 2021-02-25
 */
@RestController
@Api(value = "商户管理员相关接口", tags = {"商户管理员相关接口"})
@RequestMapping("/companyAdminR")
@Slf4j
public class CompanyAdminRRestApi {

    @Autowired
    private LocalApiConfig localApiConfig;
    @Autowired
    private CompanyAdminRService companyAdminRService;

    @AuthorityVerify
    @ApiOperation(value = "获取商户管理员列表", notes = "获取商户管理员列表", response = String.class)
    @PostMapping("/getList")
    public String getList(@Validated({GetList.class}) @RequestBody CompanyAdminRVO companyAdminRVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("获取商户管理员列表: {}", companyAdminRVO);
        return ResultUtil.successWithData(companyAdminRService.getPageList(companyAdminRVO));
    }

    @AuthorityVerify
    @ApiOperation(value = "获取商户管理员列表", notes = "获取商户管理员列表", response = String.class)
    @PostMapping("/getAllList")
    public String getAllList(@Validated({GetList.class}) @RequestBody CompanyAdminRVO companyAdminRVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("获取商户管理员列表: {}", companyAdminRVO);
        return ResultUtil.successWithData(companyAdminRService.getAllList(companyAdminRVO));
    }

//    @AuthorityVerify
//    @OperationLogger(value = "新增商户管理员")
//    @ApiOperation(value = "新增商户管理员", notes = "新增商户管理员", response = String.class)
//    @PostMapping("/add")
//    public String add(@Validated({Insert.class}) @RequestBody CompanyAdminRVO companyAdminRVO, BindingResult result) {
//        ThrowableUtils.checkParamArgument(result);
//        log.info("新增商户管理员: {}", companyAdminRVO);
//        if (localApiConfig.localMode) {
//            return companyAdminRService.localAdd(companyAdminRVO);
//        } else {
//            return companyAdminRService.add(companyAdminRVO);
//        }
//    }

    @AuthorityVerify
    @OperationLogger(value = "修改商户管理员")
    @ApiOperation(value = "修改商户管理员", notes = "修改商户管理员", response = String.class)
    @PostMapping("/edit")
    public String edit(@Validated({Update.class}) @RequestBody CompanyAdminRVO companyAdminRVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("修改商户管理员: {}", companyAdminRVO);
        return companyAdminRService.edit(companyAdminRVO);
    }

    @AuthorityVerify
    @OperationLogger(value = "删除商户管理员")
    @ApiOperation(value = "删除商户管理员", notes = "删除商户管理员", response = String.class)
    @PostMapping("/delete")
    public String delete(@Validated({Delete.class}) @RequestBody CompanyAdminRVO companyAdminRVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("删除商户管理员: {}", companyAdminRVO);
        return companyAdminRService.delete(companyAdminRVO);
    }

//    @AuthorityVerify
//    @OperationLogger(value = "商户操作员管理功能开关")
//    @ApiOperation(value = "商户操作员管理功能开关", notes = "商户操作员管理功能开关", response = String.class)
//    @PostMapping("/roleSwitch")
//    public String roleSwitch(@Validated({Delete.class}) @RequestBody CompanyAdminRVO companyAdminRVO, BindingResult result) {
//        ThrowableUtils.checkParamArgument(result);
//        log.info("商户操作员管理功能开关: {}", companyAdminRVO);
//        return companyAdminRService.roleSwitch(companyAdminRVO);
//    }

    @AuthorityVerify
    @ApiOperation(value = "获取商户管理员列表", notes = "获取商户管理员列表", response = String.class)
    @PostMapping("/getCompanyAdminList")
    public String getCompanyAdminList(@RequestBody CompanyAdminRVO companyAdminRVO) {
        log.info("获取商户管理员列表: {}", companyAdminRVO);
        return ResultUtil.successWithData(companyAdminRService.getCompanyAdminList(companyAdminRVO));
    }

    @AuthorityVerify
    @ApiOperation(value = "获取我的商户列表", notes = "获取我的商户列表", response = String.class)
    @PostMapping("/getAllMyCompanyList")
    public String getAllMyCompanyList(@RequestBody CompanyAdminRVO companyAdminRVO) {
        log.info("获取我的商户列表: {}", companyAdminRVO);
        return ResultUtil.successWithData(companyAdminRService.getMyCompanyList());
    }

    @AuthorityVerify
    @ApiOperation(value = "获取当前商户管理员列表", notes = "获取当前商户管理员列表", response = String.class)
    @PostMapping("/getPresentCompanyAdminList")
    public String getPresentCompanyAdminList(@RequestBody CompanyAdminRVO companyAdminRVO) {
        log.info("获取当前商户管理员列表: {}", companyAdminRVO);
        return ResultUtil.successWithData(companyAdminRService.getPresentCompanyAdminList(companyAdminRVO));
    }

    @AuthorityVerify
    @ApiOperation(value = "获取当前用户可被推送商户", notes = "获取当前用户可被推送商户", response = String.class)
    @PostMapping("/getPushAbleAdminInfoList")
    public String getPushAbleAdminInfoList(@RequestBody CompanyAdminRVO companyAdminRVO) {
        log.info("获取当前用户可被推送商户: {}", companyAdminRVO);
        return ResultUtil.successWithData(companyAdminRService.getPushAbleAdminInfoList(companyAdminRVO));
    }
}
